﻿<script type="text/javascript">
    $.parser.onComplete = function () {
        var d = new Date();
        d.setDate(d.getDate() - 1);
        var year = d.getFullYear();
        var month = d.getMonth() + 1;
        var day = d.getDate();
        $("#riqi_kucun").datebox('setValue',year+'-'+month+'-'+day);

        $("#kucun_zhandian").combobox({
            url: 'json/zhandian.json',
            method: 'get',
            valueField: 'zhandian',
            textField: 'zhandian',
            panelWidth: 175,
            panelHeight: 'auto',
            editable: false,
            onLoadSuccess: function () {
                $("#kucun").datagrid({
                    url: "handler/hesuan_kucun.ashx",
                    method: "get",
                    queryParams: {
                        requestType:'1',
                        uid: window.uid,
                        kid: window.kid,
                        kaishi: $("#riqi_kucun").datebox('getValue'),
                        zhandian: $("#kucun_zhandian").combobox('getText')
                    },
                    height: document.body.scrollHeight - 180,
                    loadFilter: function (data) {
                        for (var i = 0; i < data.length; i++) {
                            data[i].riqi = data[i].riqi.substring(0, 10);
                        }
                        return data;
                    }
                });
            }
        });
    }

    var toolbar_kucun = [{
        text: '库存调差',
        iconCls: 'icon-edit',
        handler: function () {
            var curRow = $("#kucun").datagrid('getSelected');
            if (curRow) {
                $("#info-tiaocha").textbox('setValue', curRow.tiaocha);
                $("#tiaocha-edit").dialog('open');
                $("#tiaochaID").val(curRow.id);
            }
            else {
                alert('请选择库存信息。');
            }
        }
    }];

    $("#chaxun_kucun").click(function () {
        $("#kucun").datagrid('load', {
            requestType:'1',
            uid: window.uid,
            kid: window.kid,
            kaishi: $("#riqi_kucun").datebox('getValue'),
            zhandian: $("#kucun_zhandian").combobox('getText')
        });
    });

    $("#daochu_kucun").click(function () {
        //导出
        var dateKaiShi = $("#riqi_kucun").datetimebox('getValue');
        var zhanDianStr = $("#kucun_zhandian").combobox('getText').replace('#', "_");
        var yongHu = $("#currentUser").text();
        window.open(encodeURI("http://keaomds.com:10001/?uid=" + window.uid + "&kid=" + window.kid + "&requestType=10&keHuBianHao=" + window.kehubianhao + "&zhandian=" + zhanDianStr + "&kaishi=" + dateKaiShi + "&yonghu=" + yongHu));

    });

    function submittiaochaFrom() {
        var tiaocha = $("#info-tiaocha").textbox('getValue');
        if (tiaocha) {
            $.get('handler/hesuan_kucun.ashx', { requestType: '2', tiaochaID: $("#tiaochaID").val(), uid: window.uid, kid: window.kid,tiaocha:tiaocha }, function (data, status) {
                if (data == "OK") {
                    $("#tiaocha-edit").dialog('close');
                    $("#kucun").datagrid('load', {
                        requestType: '1',
                        uid: window.uid,
                        kid: window.kid,
                        kaishi: $("#riqi_kucun").datebox('getValue'),
                        zhandian: $("#kucun_zhandian").combobox('getText'),
                        gengxin:'OK'
                    });
                }
                else {
                    alert(data);
                }
            });
        }
        else {
            alert('请输入调差数值。');
        }
    }

    function cleartiaochaForm()
    {
        $("#tiaocha-edit").dialog('close');
    }

</script>

<div class="easyui-panel" data-options="height:90,border:false" title="数据检索" style="border-top-width: 0px;
    border-bottom-width: 1px; padding: 15px; width:100%">
    <table style="font-size: 12px;">
        <tr>
            <td>
                站点：
            </td>
            <td>
                <input class="easyui-combobox" name="kucun_zhandian" id="kucun_zhandian" style="width: 175px;" />
            </td>
            <td>
                库存日期：
            </td>
            <td>
                <input id="riqi_kucun" type="text" class="easyui-datebox" data-options="required:true"
                       style="width: 120px">
            </td>
            <td>
                <a id="chaxun_kucun" class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                   style="width: 60px; margin-left: 20px;">查询</a>
            </td>
            <td>
                <a id="daochu_kucun" class="easyui-linkbutton" data-options="iconCls:'icon-export-16'"
                   style="width: 60px">导出</a>
            </td>
          
        </tr>
    </table>
</div>

<table id="kucun" class="easyui-datagrid" title="库存查询" data-options="border:false,singleSelect:true,collapsible:false,striped:true,fitColumns:true,toolbar:toolbar_kucun" style="width:100%">
    <thead>
        <tr>
            <th data-options="field:'riqi'">
                日期
            </th>
            <th data-options="field:'wuliaomingcheng'">
                物料名称
            </th>
            <th data-options="field:'xinghaomingcheng'">
                型号
            </th>
            <th data-options="field:'jieyu'">
                昨日结余(t)
            </th>
            <th data-options="field:'ruku'">
                入库重量(t)
            </th>
            <th data-options="field:'chuku'">
                出库重量(t)
            </th>
            <th data-options="field:'tiaocha'">
                盘存调差(t)
            </th>
            <th data-options="field:'kucun'">
                库存(t)
            </th>
        </tr>
    </thead>
</table>

<div id="tiaocha-edit" class="easyui-dialog" title="库存调差" data-options="modal:true,closed:true,iconCls:'icon-edit',draggable:false,collapsible:false,minimizable:false,maximizable:false,resizable:false"
     style="width: 500px; height: 200px; padding: 10px;">
    <div style="width: 350px; margin: 0 auto;">
        <table cellpadding="5" style="font-size: 13px; margin: 0 auto; padding-top: 20px">
            <tr>
                <td>
                    调差值:
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info-tiaocha" name="info-tiaocha"
                           data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <span style="color:red; font-size:small">*库存=昨日结余+入库重量-出库重量+盘存调差</span>
                </td>
            </tr>
        </table>
        <input type="hidden" name="tiaochaID" id="tiaochaID" value="" />
        <div style="text-align: center; padding: 5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="submittiaochaFrom()" data-options="iconCls:'icon-ok'">保存</a> 
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="cleartiaochaForm()" data-options="iconCls:'icon-cancel'">关闭</a>
        </div>
    </div>
</div>